﻿<html>
<head>
	<TITLE>Quản lý thông tin đối tác</TITLE>	
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript">
   	$(document).ready(function(){
		$("#birthday").datepicker({dateFormat:"dd-mm-yy"});
		$('#insert_acc').hide();
		$('#status1').hide();
		$('#status2').hide();
		$('#fax').hide();
		load_accounttype();
		query(1);
		load_listpage(1);
		$("#username").keypress(function (e){
		  	var keycode;
			if (window.event) keycode = window.event.keyCode;
			else if (e) keycode = e.which;
			else return true;
			if (keycode == 13){
				query(1);
				load_listpage(1);
				return false;
			}else{
				return true;
			}
		});
		$("#name").keypress(function (e){
		  	var keycode;
			if (window.event) keycode = window.event.keyCode;
			else if (e) keycode = e.which;
			else return true;
			if (keycode == 13){
				query(1);
				load_listpage(1);
				return false;
			}else{
				return true;
			}
		});
	});
	/*
	*/
   	function query(page){
		var username=$("#username").val();
		var name= $('#name').val();
		var per_page= $('#per_page').val();
		//alert();
		var path='username='+username+'&name='+name+'&page='+page+'&per_page='+per_page;
		//alert(path);
		$.ajax({
      			type:"POST",
      			url: "data/system/account/account_manager/totalPage.php",
      			data: path,
                async: false,
    			success: function(data) {
		            //alert(data);
    				$("#totalPage").html(data);
                    //$('#dsMenuTab').tableFilter(true);
                    $('#total_row').val(data);
			     }
		});
		$.ajax({
      			type:"POST",
      			url: "data/system/account/account_manager/list_account.php",
      			data: path,
                async: false,
    			success: function(data) {  
						//alert(data);
						 $('#dsAccountList').html(data);
						 $('#dsAccountTab').tableFilter(true);
			     }
		     }); 
	}
	
	function load_listpage(page){
       	    var username=$("#username").val();
			var name= $('#name').val();
			var per_page= $('#per_page').val();
			//alert();
			var path='username='+username+'&name='+name+'&page='+page+'&per_page='+per_page;
            //alert(path);
            $.ajax({
      			type:"POST",
      			url: "data/system/account/account_manager/list_page.php",
      			data: path,
                async: false,
    			success: function(data) {
                    var total=$('#total_row').val();
                    if(total/per_page>1){
    				    $("#listpage_data").html(data);
                        $('#listpage').show();
                    }else {
                        $("#listpage_data").html("");
                        $('#listpage').hide();
                        
                    }
			     }
		     }); 
    }
	
    function load_accounttype(){
            var path ='';
            $.ajax({
      			type:"POST",
      			url: "data/system/account/user_info/get_list_accounttype.php",
      			data: path,
                async: false,
    			success: function(data) {                   
                        $("#combox_accounttype").html(data);
						$("#level").removeAttr('disabled');        
			     }
		     }); 
	}
	function update_userinfo(){
			 var username =$('#username_form').val();
			 var password =$('#password').val();
			 var first_name =$('#first_name').val();
			 var last_name =$('#last_name').val();
			 var birthday =$('#birthday').val();
			 var address =$('#address').val();
			 var mobi = $('#mobi').val();
			 var tell = $('#tell').val();
			 var zoom_number = $('#zoom_number').val();
			 var email = $('#email').val();
			 var level=$('#level').val();
			 var modified_date =$('#modified_date').val();
			 var created_date = $('#created_date').val();
			 var created_by =$('#created_by').val();
			 var fax =$('#fax').val();
			 var sex=0;
			 if($("#rdSEXM").attr("checked"))  sex=1;
			 var status=0;
			 if($("#status2").attr("checked"))  status=1;
			 var partner_id = $('#partner_id').val();
			 var path='username='+username+'&password='+password+'&first_name='+first_name+'&last_name='+last_name+'&birthday='+birthday+
			 			'&address='+address+'&mobi='+mobi+'&tell='+tell+'&zoom_number='+zoom_number+'&email='+email+'&level='+level+                        '&modified_date='+modified_date+'&created_date='+created_date+'&created_by='+created_by+'&fax='+fax+'&sex='+sex+                        '&status='+status;
			 
			 //alert(path);
             $.ajax({
      			type:"POST",
      			url: "data/system/account/user_info/edit_user_info.php",
      			data: path,
                async: false,
    			success: function(data) {  
						// alert(data); 
						 if(data==1) {
							 _alert('inform','Cập nhật thông tin account:'+username+' thành công');
							 query(1);
						 	 load_listpage(1);
							}              
                         else _alert('inform','Cập nhật thông tin account:'+username+' không thành công!');
						 
			     }
		     }); 
		
	}
	function insert_account(){
			
			 var username =$('#username_form').val();
			 var password =$('#password').val();
			 var first_name =$('#first_name').val();
			 var last_name =$('#last_name').val();
			 var birthday =$('#birthday').val();
			 var address =$('#address').val();
			 var mobi = $('#mobi').val();
			 var tell = $('#tell').val();
			 var zoom_number = $('#zoom_number').val();
			 var email = $('#email').val();
			 var level=$('#level').val();
			// var modified_date =$('#modified_date').val();
			 //var created_date = $('#created_date').val();
			 //var created_by =$('#created_by').val();
			 var fax =$('#fax').val();
			 var sex=0;
			 if($("#rdSEXM").attr("checked"))  sex=1;
			 var status=0;
			 if($("#status2").attr("checked"))  status=1;
			 var partner_id = $('#partner_id').val();
			 var path='username='+username+'&password='+password+'&first_name='+first_name+'&last_name='+last_name+'&birthday='+birthday+
			 			'&address='+address+'&mobi='+mobi+'&tell='+tell+'&zoom_number='+zoom_number+'&email='+email+'&level='+level+                        '&fax='+fax+'&sex='+sex+'&status='+status;
			// alert(path);
             $.ajax({
      			type:"POST",
      			url: "data/system/account/account_manager/insert_account.php",
      			data: path,
                async: false,
    			success: function(data) {  
						 //alert(data); 
						 if(data==1) {
							 _alert('inform','Thêm account:'+username+' thành công'); 
							 query(1);
						 	 load_listpage(1);
							}             
                         else _alert('inform','Thêm account:'+username+' không thành công!');
						 
			     }
		     }); 
		
	}
	function detailInfoAccount(obj){
				viewFormInfo();
				loadAccountInfo(obj);
	}
	
	function edit_info_acc(obj){
				//alert("aa");
				viewFormEdit();
				loadAccountInfo(obj);
	}
	function reset_form(){
		$("#username_form").removeAttr("disabled");
		$("#password").removeAttr("disabled");
		$("#first_name").removeAttr("disabled");
		$("#last_name").removeAttr("disabled");
		$("#birthday").removeAttr("disabled");
		$("#address").removeAttr("disabled");
		$("#mobi").removeAttr("disabled");
		$("#rdSEXM").removeAttr("disabled");
		$("#rdSEXF").removeAttr("disabled");
		$("#tell").removeAttr("disabled");
		$("#zoom_number").removeAttr("disabled");
		$("#email").removeAttr("disabled");
		$("#fax").removeAttr("disabled");
		$("#level").removeAttr("disabled");
		$("#created_by").removeAttr("disabled");
		$("#created_date").removeAttr("disabled");
		$("#modified_date").removeAttr("disabled");
		$("#status1").removeAttr("disabled");
		$("#status2").removeAttr("disabled");
		
	}
	function viewFormInfo(){
		$('#title_form').html('Thông tin chi tiết');
		$('#insert_acc').show();
		$('#cmdOK1').hide();
		$('#cmdOK2').hide();
		$("#username_form").attr("disabled","disabled");
		$("#password").attr("disabled","disabled");
		$("#first_name").attr("disabled","disabled");
		$("#last_name").attr("disabled","disabled");
		$("#birthday").attr("disabled","disabled");
		$("#address").attr("disabled","disabled");
		$("#mobi").attr("disabled","disabled");
		$("#rdSEXM").attr("disabled","disabled");
		$("#rdSEXF").attr("disabled","disabled");
		$("#tell").attr("disabled","disabled");
		$("#zoom_number").attr("disabled","disabled");
		$("#email").attr("disabled","disabled");
		$("#fax").attr("disabled","disabled");
		$("#level").attr("disabled","disabled");
		$("#created_by").attr("disabled","disabled");
		$("#created_date").attr("disabled","disabled");
		$("#modified_date").attr("disabled","disabled");
		$("#status1").attr("disabled","disabled");
		$("#status2").attr("disabled","disabled");
		//$("#username_form").attr("disabled","disabled");
	
	}
	function viewFormInsert(){
		$('#title_form').html('Thêm mới	account');
		reset_form();
		$('#insert_acc').show();
		$("#action").show();
		$('#cmdOK1').show();
		$('#cmdOK2').hide();
		$("#update_info_acc").hide();
		$("#created_by").attr("disabled","disabled");
		$("#created_date").attr("disabled","disabled");
		$("#modified_date").attr("disabled","disabled");
		
		$("#username_form").val('');
		$("#password").val('');
		$("#first_name").val('');
		$("#last_name").val('');
		$("#birthday").val('');
		$("#address").val('');
		$("#mobi").val('');
		$("#rdSEXM").val('');
		$("#rdSEXF").val('');
		$("#tell").val('');
		$("#zoom_number").val('');
		$("#email").val('');
		$("#fax").val('');
		$("#level").val('');
		$("#created_by").val('');
		$("#created_date").val('');
		$("#modified_date").val('');
		$("#status1").val('');
		$("#status2").val('');
		
	}
	function viewFormEdit(){
		$('#title_form').html('Thay đổi thông tin account');
		$('#insert_acc').show();
		$('#cmdOK1').hide();
		$('#cmdOK2').show();
		reset_form();
		$("#action").hide();
		$("#update_info_acc").show();
		$("#username_form").attr("disabled","disabled");
		$("#password").attr("disabled","disabled");
		//$("#level").attr("disabled","disabled");
		$("#created_by").attr("disabled","disabled");
		$("#created_date").attr("disabled","disabled");
		$("#modified_date").attr("disabled","disabled");
	
	}
	
	function hide_formInsert(){
		$('#insert_acc').hide();
	}
	
	function loadAccountInfo(obj){
		//alert('aaaa');
		var cells =	obj.getElementsByTagName('td');
		$('#username_form').val(cells[1].innerHTML);
		$('#password').val(cells[2].innerHTML);
		//alert('aaaa');
		$('#first_name').val(cells[3].getElementsByTagName('input')[0].value);
		$('#last_name').val(cells[3].getElementsByTagName('input')[1].value);
		$('#birthday').val(cells[0].getElementsByTagName('input')[0].value);
		$('#address').val(cells[5].getElementsByTagName('input')[0].value);
		$('#mobi').val(cells[6].getElementsByTagName('input')[0].value);
		$('#tell').val(cells[6].getElementsByTagName('input')[1].value);
		if(cells[8].getElementsByTagName('input')[1].value == '1') $('#rdSEXM').attr('checked',true);
		else $('#rdSEXF').attr('checked',true);
		if(cells[8].getElementsByTagName('input')[0].value == '1') $('#status2').attr('checked',true);
		else $('#status1').attr('checked',true)
		$('#zoom_number').val(cells[7].getElementsByTagName('input')[0].value);
		$('#email').val(cells[4].innerHTML);
		$('#level').val(cells[9].getElementsByTagName('input')[3].value);
		$('#fax').val(cells[6].getElementsByTagName('input')[2].value);
		$('#created_by').val(cells[5].getElementsByTagName('input')[1].value);
		$('#created_date').val(cells[9].getElementsByTagName('input')[1].value);
		$('#modified_date').val(cells[9].getElementsByTagName('input')[2].value);
		//alert('the end');
	}
	function delete_account(id){
		if(!confirm("Bạn có muốn xóa Account này trên hệ thống không?")) return;
		alert('aaa');
		$.ajax({
      			type:"POST",
      			url: "data/system/account/account_manager/delete_account.php",
      			data: 'username='+id,
                async: false,
    			success: function(data) {  
						 alert(data); 
						 if(data==1) {
							 _alert('inform','Xóa account:'+id+' thành công'); 
							 query(1);
						 	 load_listpage(1);
							}             
                         else _alert('inform','Xóa account:'+id+' không thành công!');
						 
			     }
		     }); 
		
	}
	function avaiable_data(){
		var user_id =$().val();
		
	
	}
   </script>
</head>
<BODY>
   <div id='tabheader' class="header">システム管理&nbsp;<img height="7px" src="lib/images/left.png">&nbsp; ユーザ管理 </div>
    <div>
		<fieldset class="field_set">
			<legend>索引</legend>
			<table width="100%" id="dsFindTab" class='ctable' >
				<tr>
					<td style="padding-right:10px;" width="20%" align="right">ユーザID</td>
					<td width="20%"><input type="text" id="username" width="80%" class="cinput" ></td>
					<td width="5%" style="padding-right:10px;">氏名</td>
					<td width="20%"><input  type="text" name="name" id="name" width="80%" class="cinput"></td>
				  <td width="35%" align="center"><INPUT id='query_account' style="width:100px" type="button" value="索引" class="gra_button green" onClick="query(1);
				load_listpage(1);">
						
					</td>
				</tr>
				<tr><td colspan="4" align="center"><div id="inform"></div></td></tr> 
			</table>
		</fieldset>

		
		<div class="padding10"></div>
		
		
	
		
		
		<div>
			<fieldset class="field_set">
				<legend>User account list</legend>
				<div id="phantrang">
					<table class="ctable"  width="100%" style="margin-bottom: 0px; height: 40px; vertical-align: middle;">
					<tr align="center">
						<td align="left" width="20%">総計<strong>
						<div id="totalPage" style="display:inline;"></div></strong>&nbsp;レコード<input type="hidden" id='total_row'></td>
						<td width="60%" style="display:inline;">
						  <div id="listpage"><a href="javascript:query(1);load_listpage(1)" class="page">一番目のページ</a><div id="listpage_data" style="display: inline;"></div><a style="display: inline;" href="javascript:GoEndPage()">最後のページ</a>
						</div></td>
						<td align="right" width="20%" style="display:inline;">表す &nbsp;<select id="per_page" onChange="load_listpage(1);query(1)" style="margin-top: 5px;">
							<option value="10">10 レコード</option>
							<option value="15">15 レコード</option>
							<option value="100">100 レコード</option>
						</select></td>
					 </tr>
				 </table>       
				</div>
				<div id="dsAccountList" style="padding:0;width:100%;border:1px;">
				
				</div>
			</fieldset>
		 </div>
		 
		 <INPUT id='insert_account' style="width:100px" type="button" value="新しい" class="gra_button green" onClick="viewFormInsert()">
		 <div class="padding10"></div>
		 <div id="insert_acc">
			<fieldset class="field_set">
				<legend><div id="title_form">Them moi</div></legend>
				<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 class="ctable">
				  <TBODY>
					  <TR>
						<TD width="25%" style="padding-left:100px;">ユーザID<font color="#FF0000">*</font> : </TD>
						<TD style="VERTICAL-ALIGN: top; PADDING-TOP: 4px" width="25%">
						<input id="username_form" class=cinput type="text" style="WIDTH: 100%" name="USERID"></TD>
						<TD width="25%" style="padding-left:100px;">パースワード<font color="#FF0000">* </font>:</TD>
						<TD width="25%"><input id="password" class=cinput type="password" style="WIDTH: 100%" name="password"></TD></TR>
					  <TR>
						<TD style="padding-left:100px;">族名<font color="#FF0000">&nbsp; </font><font color="#FF0000">&nbsp;*</font> : </TD>
						<TD>
							<input id="first_name"  class=cinput type="text" style="WIDTH:100%" name="first_name" ></TD>
						<TD style="padding-left:100px;">氏名: </TD>
						<TD width="212" ><input id="last_name"  class=cinput type="text" style="WIDTH: 100%" name="last_name" >
						</TD>
						</TR>
				
					  <TR>
						<TD style="padding-left:100px;">生年月日 <font color="#FF0000">*</font> : </TD>
						<TD >
							<input style="WIDTH:70%" class="cdate" type="text" name="birthday" id="birthday" />
						</TD>
						<TD style="padding-left:100px;">
						
					   住所 <font color="#FF0000">*</font> :
						</TD>
						<TD width="212">
							<input id="address" class=cinput type="text" style="WIDTH: 100%" name="ADDRESS" ></TD></TR>
					  <TR>
						<TD style="padding-left:100px;">電話番号<font color="#FF0000">*</font> : </TD>
						<TD >
							<input id="mobi" class=cinput type="text" style="WIDTH: 100%" name="MOBILE" ></TD>
						<TD style="padding-left:100px;">性的<font color="#FF0000">* </font>:</TD>
						<TD width="212" >
							<input id="rdSEXM" type="radio" value="1" name="sex">
							男
							<input id="rdSEXF" type="radio" value="2" name="sex">
							女
						</TD></TR>
						<tr>
						<TD style="padding-left:100px;">固定の電話番号<font color="#FF0000">*</font> : </TD>
						<TD>
							<input id="tell" class=cinput type="text" style="WIDTH: 100%" name="TEL" ></TD>
						<TD style="padding-left:100px;">会議室の番号 :</TD>
						<TD width="212">
							<input id="zoom_number" class=cinput type="text" style="WIDTH: 100%"  name="zoom_number"></TD>
						</tr>
						<tr>
						<TD style="padding-left:100px;">メール<font color="#FF0000">*</font> :</TD>
						<TD>
							<input id="email" class=cinput type="text" style="WIDTH: 100%"  name="EMAIL" ></TD>
						<TD style="padding-left:100px;">権限</TD>
						<TD width="212"><div id="combox_accounttype"></div></TD>
						</tr>
						<tr>
                        <TD style="padding-left:100px;">作成者:</TD>
						<TD>
							<input id="created_by"  type="text" class="cinput" />
						</TD>
						<TD style="padding-left:100px;">&nbsp;</TD>
						<TD>	 
						</TD>
						</tr>
						<tr>
						<TD style="padding-left:100px;">作成の生年月日:</TD>
						<TD>
							<input id="created_date"  type="text" class="cdate" style="width:90%"/>
						</TD>
						<TD style="padding-left:100px;">編成の生年月日：</TD>
						<TD>
							<input id="modified_date"  type="text" class="cdate" />
						</TD
						></tr>
						<tr>
							 <TD colspan="4" align="center"><div id='inform'></div></TD>
						</tr>
						<tr>
							<TD colspan="3" align="center">
							<div class="padding5"></div>
							<INPUT id='cmdOK1' style="width:200"  type=button value="実施" onClick="insert_account()" class="gra_button green">
							<INPUT id='cmdOK2' style="width:200"  type=button value="編成" onClick="update_userinfo()" class="gra_button green"></TD>
							<td align="right"><a href='javascript: hide_formInsert()'><span> フォームを押し</span></a></td>
						</tr>
				  </TABLE>
				</fieldset>
			  <div class="padding10"></div>
		</div>
    
</div>
<input id="status1" type="radio" value="0" name="STATUS" checked>
							
							<input id="status2"  type="radio" value="1" name="STATUS">
                            <input id="fax" class=cinput type="text" style="WIDTH: 100%"  name="fax" >
</BODY>
</HTML>